package com.dongdongshop.service.imp;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.page.PageBeen;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.service.TbBrandService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
@org.springframework.stereotype.Service
public class TbBrandServiceImp implements TbBrandService {

    @Autowired
    private TbBrandMapper tbBrandMapper;
    @Override
    public PageBeen<TbBrand> getTbBrand(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbBrand> brandList = tbBrandMapper.selectByExample(null);
        PageInfo<TbBrand> page = new PageInfo<>(brandList);
        PageBeen<TbBrand> pageInfo = new PageBeen<>(pageNum,pageSize,page.getTotal(),page.getList(), page.getPages());
        return pageInfo;
    }

    @Override
    public Integer addBrand(TbBrand tbBrand) {
        return tbBrandMapper.insertSelective(tbBrand);
    }


    @Override
    public TbBrand toUpdate(Long id) {
        TbBrand tbBrand = tbBrandMapper.selectByPrimaryKey(id);
        return tbBrand;
    }

    @Override
    public int updateInfo(TbBrand tbBrand) {
        return tbBrandMapper.updateByPrimaryKeySelective(tbBrand);
    }

    @Override
    public Integer deleteInfo(Integer[] ids) {
        return tbBrandMapper.deleteInfo(ids);
    }


}
